home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-02-09 | 27.6 KB | 828 lines | [TEXT/MPS ] |
- {
- File Chroma.p
-
- This is a DA to show the current color assignments of all
- connected displays, without taking up the whole screen
- (unless you want to zoom the window!).
-
- By Greg Marriott
- Special thanks to Scott T. Boyd, Chris Derossi, & Darin Adler
-
- Copyright 1988, The MacHax™ Group.
- All rights reserved.
-
- 1.0d1 1-23-88 Created DA that puts up a window, and
- plots colors of MainDevice
- 1.0d2 1-24-88 Made window wider, added slot number of
- MainDevice
- 1-24-88 Beefed up error detection(but not
- necessarily correction %-)
- 1.0d3 1-25-88 Added brag pictures, b/w pictures
- 1-25-88 Call SysEnvirons to detect colorQD
- 1-25-88 Added word 'Slot' above slot number
- 1.0d4 1-26-88 Miscellaneous bug/cosmetic fixes
- 1.0d5 1-28-88 Made updates smarter. Now it clips to
- each device and draws with their
- characteristics(i.e. depth and color
- table)
- 1-28-88 Added zooming, then fixed zooming
- 1-29-88 Revised zooming to fill device of
- interest, instead of main device
- 1.0b1 1-29-88 Revved to beta and selected testers
- 1.0b2 2- 4-88 Scott made zooming work right, allowing
- the use of FindWindow.
- 1.0b3 2- 7-88 Began to use Palette Manager, as Chris
- suggested.
- 2- 8-88 Added more slot info to window, including
- gdFlags, gdRefNum, and gdMode, all hex
- numbers.
- 2- 8-88 Revised zooming, added option-zoom feature
- 1.0 2- 9-88 Published!
- }
-
- {$D+} { Debugging symbols on }
-
- UNIT Chroma;
-
- INTERFACE
-
- USES
- MemTypes, QuickDraw, OSIntf, ToolIntf, PaletteMgr, PackIntf;
-
-
- FUNCTION DRVROpen(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
- FUNCTION DRVRControl(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
- FUNCTION DRVRStatus(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
- FUNCTION DRVRPrime(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
- FUNCTION DRVRClose(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
-
-
- IMPLEMENTATION
-
- CONST
- versID = '1.0';
- windowVSize = 96;
-
- bwChromaPicture = 0;
- colorChromaPicture = 1;
- sorryPicture = 2;
-
- infoStrings = 0;
- firstInfoStr = 1;
- slotStr = 1;
- refNumStr = 2;
- flagsStr = 3;
- modeStr = 4;
- lastInfoStr = 4;
-
- TYPE
- ChromaStorage = RECORD
- theDevice:GDHandle;
- minSize:Point;
- windowPlace:Rect;
- hasColorQD:Boolean;
- END;
- ChromaStoragePtr = ^ChromaStorage;
- ChromaStorageHandle = ^ChromaStoragePtr;
-
- EventPtr = ^EventRecord;
- trix = RECORD { needed for some coercive behavior }
- CASE Boolean of
- TRUE : (dontCare:ARRAY[0..10] OF Integer);
- FALSE : (theEventPtr: EventPtr);
- END;
-
- WStatePtr = ^WStateData;
- WStateHandle = ^WStatePtr;
-
- FUNCTION RsrcID(dCtl:DCtlPtr;localID:INTEGER):Integer;
- BEGIN
- { Calculate resource ID's based on our refNum }
- RsrcID := (BOR($C000,(BSL(BNOT(dCtl^.dCtlRefNum),5))))
- + localID;
- END;
-
- FUNCTION DRVROpen(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
-
- FUNCTION MinWindowSize:Point;
- VAR
- theStringList:Handle;
- theString:Str255;
- widest:INTEGER;
- i:INTEGER;
- BEGIN
- { The vertical minimum is predetermined }
- MinWindowSize.v := windowVSize;
- widest := 0;
-
- { Read all the strings, finding the widest one }
- FOR i := firstInfoStr TO lastInfoStr DO
- BEGIN
- GetIndString(theString, RsrcID(dCtl, infoStrings), i);
- IF StringWidth(theString) > widest THEN
- widest := StringWidth(theString);
- END;
-
- { Add a little margin }
- widest := widest + 2;
- MinWindowSize.h := windowVSize + widest;
- END; { FUNCTION MinWindowSize }
-
- VAR
- oldPort:GrafPtr;
- wFrame:Rect;
- myWindow:WindowPtr;
- myWindowSize:Point;
- theEnv:SysEnvRec;
- envError:OSErr;
- aPalette:PaletteHandle;
-
- BEGIN
- { If there's no window yet, put one up... }
- IF dCtl^.dCtlWindow = NIL THEN
- BEGIN
- { Pick a size for the window, even though we're
- gonna change that before the window becomes visible }
- SetRect(wFrame, 0, 0, windowVSize, windowVSize);
- OffSetRect(wFrame, 100, 100);
-
- { Ask SysEnvirons if we have colorQD. If not, put up
- a "regular" window instead of a color window }
- envError := SysEnvirons(1, theEnv);
- IF theEnv.hasColorQD THEN
- myWindow := NewCWindow(NIL, wFrame, 'Chroma', FALSE,
- zoomNoGrow, WindowPtr(-1), TRUE,
- LongInt(0))
- ELSE
- myWindow := NewWindow(NIL, wFrame, 'Chroma', FALSE,
- noGrowDocProc, WindowPtr(-1), TRUE,
- LongInt(0));
-
- { If the window was created OK, figure out how big
- the window should be and then fill in some
- important fields }
- IF myWindow <> NIL THEN
- BEGIN
- { Start by setting the text parameters and computing
- a minimum size for the window }
- SetPort(myWindow);
- TextMode(SrcOr);
- TextFont(Geneva);
- TextSize(9);
- TextFace([]);
- myWindowSize := MinWindowSize;
-
- { Set the window to the minimum size, and show it }
- SizeWindow(myWindow, myWindowSize.h, myWindowSize.v,
- FALSE);
- ShowWindow(myWindow);
- SelectWindow(myWindow);
-
- { This one shows that a DA owns the window }
- WindowPeek(myWindow)^.WindowKind := dCtl^.dCtlRefNum;
-
- { And this one lets the desk manager know, too }
- dCtl^.dCtlWindow := Ptr(myWindow);
-
- { We'll keep some info around in the storage field }
- dCtl^.dCtlStorage := NewHandle(SizeOf(ChromaStorage));
-
- { Note whether we put up a color window or not }
- ChromaStorageHandle(dCtl^.dCtlStorage)^^.hasColorQD :=
- theEnv.hasColorQD;
-
- { Store the minimum window size, based on the longest
- description name in the string list }
- ChromaStorageHandle(dCtl^.dCtlStorage)^^.minSize :=
- myWindowSize;
-
- IF theEnv.hasColorQD THEN
- BEGIN
- { Go get the main device, then note the window's
- global location }
- WITH ChromaStorageHandle(dCtl^.dCtlStorage)^^ DO
- BEGIN
- theDevice := GetMainDevice;
- windowPlace := WindowPeek(dCtl^.dCtlWindow)^.
- contRgn^^.rgnBBox;
- END;
-
- { Make a new palette, and "install" it }
- aPalette := NewPalette( 256, NIL, pmExplicit, 0 );
- SetPalette( myWindow, aPalette, TRUE );
- END;
- END;{ if window was created ok... }
- END;{ if window doesn't exist... }
- DRVROpen := NOErr;
- END;
-
- FUNCTION DRVRClose(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
- BEGIN
- { If there's a window up, get rid of it,
- and let the desk manager know, too }
- IF dCtl^.dCtlwindow <> NIL THEN
- BEGIN
- DisposeWindow(WindowPtr(dCtl^.dCtlWindow));
- dCtl^.dCtlWindow := NIL;
- END;
-
- { If we created storage, get rid of it }
- IF dCtl^.dCtlStorage <> NIL THEN
- DisposHandle(dCtl^.dCtlStorage);
-
- DRVRClose := NOErr;
- END;
-
- FUNCTION DRVRControl(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
-
- FUNCTION WhereIsTheDevice(whatDevice:GDHandle):INTEGER;
- CONST
- UTableBase = $11c;
- VAR
- devRefNum:Longint;
- unitTablePtr:^Ptr;
- unitTableBase:Ptr;
- theDCEHandle:AuxDCEHandle;
- theDCEHandlePtr:^AuxDCEHandle;
- BEGIN
- { Get the refnum of the gdevice we're interested in }
- devRefNum := whatDevice^^.gdRefNum;
-
- { If it's zero, return an impossible slot number }
- IF devRefNum = 0 THEN
- BEGIN
- WhereIsTheDevice := 42;
- Exit(WhereIsTheDevice);
- END;
-
- { Turn it into a unit number }
- devRefNum := BNOT(devRefNum);
-
- { Grab the unit table address }
- unitTablePtr := Pointer(UTableBase);
- unitTableBase := unitTablePtr^;
-
- { Go get the address of the device control entry
- for this unit }
- theDCEHandlePtr := Pointer(Ord4(unitTableBase)
- + devRefNum * 4);
- theDCEHandle := theDCEHandlePtr^;
-
- { Return the slot number of this driver }
- WhereIsTheDevice := theDCEHandle^^.dCtlSlot;
- END;{ FUNCTION WhereIsTheDevice }
-
- PROCEDURE CenterInWindow(VAR theRect:Rect);
- VAR
- rectSize:Point;
- chromaSize:Point;
- BEGIN
- { "Home" the rect first }
- OffsetRect(theRect, -theRect.left, -theRect.top);
-
- { Figure size of rect }
- WITH theRect DO
- SetPt(rectSize, right, bottom);
-
- { Figure size of window }
- WITH GrafPtr(dCtl^.dCtlWindow)^.portRect DO
- SetPt(chromaSize, right - left, bottom - top);
-
- { Position the rect, centered in the window }
- OffsetRect(theRect, (chromaSize.h - rectSize.h) DIV 2,
- (chromaSize.v - rectSize.v) DIV 2);
- END;{ PROCEDURE CenterInWindow }
-
- PROCEDURE DrawWindow;
-
- PROCEDURE DrawNextString(VAR drawWhere:Point;
- drawWhat:Str255;
- drawHow:Style);
- VAR
- someFontInfo:FontInfo;
- oldFace:Style;
- BEGIN
- { Save the text style }
- oldFace := GrafPtr(dCtl^.dCtlWindow)^.txFace;
- { Set the desired text face }
- TextFace(drawHow);
-
- { The "cursor" will be centered already, so move
- back half the width of the string and draw it. }
- Move(-(StringWidth(drawWhat) DIV 2), 0);
- DrawString(drawWhat);
-
- { Move the "cursor" up a line, since we're drawing
- from the bottom of the window toward the top. We're
- letting the descenders overhang, since textmode has
- been set to SrcOr and won't wipe out the overlap. }
- GetFontInfo(someFontInfo);
- drawWhere.v := drawWhere.v - someFontInfo.ascent;
- { Re-center the "cursor" for the next time }
- MoveTo( drawWhere.h, drawWhere.v );
-
- { Restore text face }
- TextFace(oldFace);
- END;{ PROCEDURE DrawNextString }
-
- PROCEDURE NumToHexString(aNumber:INTEGER;
- VAR aString:Str255);
- { Make a 4 digit hexadecimal number from an integer }
- VAR
- unsignedNum:LONGINT;
- i:INTEGER;
- aDigit:INTEGER;
- BEGIN
- { Make an unsigned hex number from the signed integer }
- IF aNumber>0 THEN
- unsignedNum := aNumber
- ELSE
- unsignedNum := aNumber + 65536;
-
- { Make sure the string has 4 digits (spaces)}
- aString := ' ';
-
- { Fill in the digits, from lsd to msd }
- FOR i := 4 DOWNTO 1 DO
- BEGIN
- aDigit := unsignedNum MOD 16;
- IF aDigit<10 THEN
- aString[i] := chr(ord('0')+aDigit)
- ELSE
- aString[i] := chr(ord('A')+aDigit-10);
- unsignedNum := unsignedNum DIV 16;
- END;
- END;{ PROCEDURE NumToHexString }
-
- VAR
- howManyColors:INTEGER;
- pixPerSide:Point;
- pixSize:Point;
- portSize:Point;
- pixNumber:INTEGER;
- oldIndex:INTEGER;
- i,j:INTEGER;
- slotNumberString:Str255;
- theFontInfo:FontInfo;
- sorryPict:Handle;
- sorryRect:Rect;
- aPalette:PaletteHandle;
- cursorPt:Point;
- theString:Str255;
- BEGIN
- IF dCtl^.dCtlWindow <> NIL THEN
- BEGIN
- WITH ChromaStorageHandle(dCtl^.dCtlStorage)^^ DO
- BEGIN
- { Prepare to draw the contents of the window }
- EraseRect(GrafPtr(dCtl^.dCtlWindow)^.portRect);
-
- { On a color Mac with CLUT device, show the colors,
- on other machines, put up a warning }
- IF hasColorQD AND (theDevice^^.gdType=clutType) THEN
- BEGIN
- { What is the size of our window? }
- WITH GrafPtr(dCtl^.dCtlWindow)^.portRect DO
- SetPt(portSize, right - left, bottom - top);
-
- { We need to know how many colors are in the
- clut of the device of interest }
- howManyColors := theDevice^^.gdPMap^^.pmTable^^
- .ctSize + 1;
-
- { Assume a square arrangement of colors,
- except for 2 color mode. Calculate pixel
- size based on vertical size of window,
- assuming that the window will always
- be wider than it is tall }
- pixPerSide.v := Round(sqrt(howManyColors));
- IF howManyColors = 2 THEN
- pixPerSide.h := 2
- ELSE
- pixPerSide.h := pixPerSide.v;
-
- pixSize.v := portSize.v DIV pixPerSide.v;
- IF howManyColors = 2 THEN
- pixSize.h := pixSize.v DIV 2
- ELSE
- pixSize.h := pixSize.v;
-
- PenSize(pixSize.h, pixSize.v);
-
- { Keep track of the pixel number and use it to
- plot the colors in the palette we'll fill
- from the device's CLUT }
- pixNumber := 0;
-
- { Fill the palette with the colors from the
- current device, and activate the changes }
- aPalette := GetPalette(WindowPtr(dCtl^.dCtlWindow));
- CTab2Palette(theDevice^^.gdPMap^^.pmTable,aPalette,
- pmExplicit,0);
- ActivatePalette(WindowPtr(dCtl^.dCtlWindow));
-
- { Plot colored pixels one row at a time,
- 'til they're all used up }
- FOR i := 0 TO(pixPerSide.v - 1) DO
- FOR j := 0 TO(pixPerSide.h - 1) DO
- BEGIN
- { Set the foreColor, and draw a dot }
- PmForeColor(pixNumber);
- MoveTo(j * pixSize.h, i * pixSize.v);
- Line(0, 0);
-
- pixNumber := pixNumber + 1;
- END;{ Plotting loop... }
-
- { Put up some device info, first figuring some
- window positions to put the text, starting at
- the bottom of the window and centered in the
- blank part of the window }
- SetPt(cursorPt, portSize.v + (portSize.h -
- portSize.v) DIV 2, portSize.v - 2 );
- MoveTo( cursorPt.h, cursorPt.v );
-
- { Put up the mode, then its resource string }
- NumToHexString(theDevice^^.gdMode, theString);
- DrawNextString(cursorPt, theString, [bold]);
- GetIndString(theString, RsrcID(dCtl,
- infoStrings), modeStr);
- DrawNextString(cursorPt, theString, []);
-
- { Put up the flags, then their resource string }
- NumToHexString(theDevice^^.gdFlags, theString);
- DrawNextString(cursorPt, theString, [bold]);
- GetIndString(theString, RsrcID(dCtl,
- infoStrings), flagsStr);
- DrawNextString(cursorPt, theString, []);
-
- { Put up the refNum, then its resource string }
- NumToHexString(theDevice^^.gdRefNum, theString);
- DrawNextString(cursorPt, theString, [bold]);
- GetIndString(theString, RsrcID(dCtl,
- infoStrings), refNumStr);
- DrawNextString(cursorPt, theString, []);
-
- { Put up the slot#, then its resource string }
- NumToHexString(WhereIsTheDevice(theDevice) - 8,
- theString);
- DrawNextString(cursorPt, theString, [bold]);
- GetIndString(theString, RsrcID(dCtl,
- infoStrings), slotStr);
- DrawNextString(cursorPt, theString, []);
-
- END { if on a mac II... }
- ELSE
- BEGIN
- { For non-color Macs, or non-clut devices,
- show a picture saying why Chroma isn't
- showing pretty colors... }
- sorryPict := GetResource('PICT',
- RsrcID(dCtl, sorryPicture));
-
- IF sorryPict <> NIL THEN
- BEGIN
- { Center the picture in the window,
- and draw it }
- sorryRect := PicHandle(sorryPict)^^.picFrame;
- CenterInWindow(sorryRect);
-
- DrawPicture(PicHandle(sorryPict), sorryRect);
- ReleaseResource(sorryPict);
- END;{ if picHandle is good... }
- END;{ non-color/non-clut condition }
-
- { Put up the version number in the top right corner}
- GetFontInfo(theFontInfo);
- MoveTo(GrafPtr(dCtl^.dCtlWindow)^.portRect.right -
- StringWidth(versID), theFontInfo.ascent);
- DrawString(versID);
- END; { WITH ChromaStorage... }
- END;{ if window exists... }
- END;{ PROCEDURE DrawWindow }
-
- FUNCTION WhichDevice(aPoint:Point):GDHandle;
- VAR
- aDevice:GDHandle;
- foundOne:Boolean;
- BEGIN
- { Get the first one, and set the initial condition }
- aDevice := GetDeviceList;
- foundOne := FALSE;
-
- WHILE (aDevice <> NIL) AND NOT foundOne DO
- { assuming it has to be in one of the devices... }
- BEGIN
- { Check to see if this is the one... }
- IF PtInRect(aPoint, aDevice^^.gdRect) THEN
- BEGIN
- WhichDevice := aDevice;
- foundOne := TRUE;
- END;
- { Get the next device in the list }
- aDevice := aDevice^^.gdNextGD;
- END;
- END;{ FUNCTION WhichDevice }
-
- FUNCTION EqualRectSize(rect1, rect2:Rect):Boolean;
- { This function is dedicated to Scott T. Boyd %-)}
- BEGIN
- EqualRectSize :=((rect1.right - rect1.left) =
- (rect2.right - rect2.left)) AND
- ((rect1.bottom - rect1.top) =
- (rect2.bottom - rect2.top));
- END;{ FUNCTION EqualRectSize }
-
- PROCEDURE ZoomIt(partCode:INTEGER; clickedWhere:Point;
- optKeyDown:Boolean);
- CONST
- mBarHeight = $BAA;
- VAR
- oldRect, newRect:Rect;
- maxHeight:INTEGER;
- menuBarHeight:^INTEGER;
- doZoom:Boolean;
- BEGIN
- { Assume we'll zoom }
- doZoom := TRUE;
- { Get the old window size, described by the
- content region }
- oldRect := WindowPeek(dCtl^.dCtlWindow)^.
- contRgn^^.rgnBBox;
-
- { If the optionKey is down, shrink the window to
- original size... unless, of course, it's already
- original size. }
- IF optKeyDown THEN BEGIN
- newRect := oldRect;
- newRect.left := newRect.right -
- ChromaStorageHandle(dCtl^.dCtlStorage)^^.
- minSize.h;
- newRect.bottom := newRect.top +
- ChromaStorageHandle(dCtl^.dCtlStorage)^^.
- minSize.v;
-
- { If it's not already small, make it small, otherwise
- DON'T ZOOM THE WINDOW! }
- IF NOT EqualRect(oldRect,newRect) THEN
- WITH WindowPeek(dCtl^.dCtlWindow)^ DO
- wStateHandle(dataHandle)^^.stdState := newRect
- ELSE
- doZoom := FALSE;
- END
- ELSE BEGIN
- { Figure out which device the zoom box was on, so we
- know which monitor to fill up with the window. }
- newRect := WhichDevice(clickedWhere)^^.gdRect;
- InsetRect(newRect, 3, 3);
- newRect.top := newRect.top + 18;{ titlebar }
- { If it's the main device, make room for menu bar }
- IF WhichDevice(clickedWhere)=GetMainDevice THEN
- BEGIN
- menuBarHeight := Pointer( mBarHeight );
- newRect.top := newRect.top + menuBarHeight^;
- END;
-
- { Make sure that the window will be wider than
- it is tall. It should be no taller than its width
- minus the slot info area on the right side. The
- info area's size can be calculated from the minSize
- width - minSize height. }
- WITH ChromaStorageHandle(dCtl^.dCtlStorage)^^ DO
- maxHeight := newRect.right - newRect.left -
- (minSize.h - minSize.v);
- { If it's higher than it should be, shorten it }
- IF newRect.bottom - newRect.top > maxHeight THEN
- newRect.bottom := newRect.top + maxHeight;
-
- { If we're not already a big window, zoom to it,
- by putting the new size in stdState. Otherwise,
- leave the old size there (from last time)}
- IF NOT EqualRect(oldRect, newRect) THEN
- WITH WindowPeek(dCtl^.dCtlWindow)^ DO
- wStateHandle(dataHandle)^^.stdState := newRect;
- END;{ if not optionkey... }
-
- IF doZoom THEN
- BEGIN
- EraseRect(GrafPtr(dCtl^.dCtlWindow)^.portRect);
- ZoomWindow(WindowPtr(dCtl^.dCtlWindow), partCode,
- false);
- InvalRect(GrafPtr(dCtl^.dCtlWindow)^.portRect);
-
- { Fool ZoomWindow into always zooming "out" by
- changing the "zoomed" window size }
- WITH WindowPeek(dCtl^.dCtlWindow)^ DO
- wStateHandle(dataHandle)^^.stdState := oldRect;
- END;
- END;{ PROCEDURE ZoomIt }
-
- PROCEDURE BragALittle;
- VAR
- aboutPict:Handle;
- aboutRect:Rect;
- BEGIN
- WITH ChromaStorageHandle(dCtl^.dCtlStorage)^^ DO
- BEGIN
- EraseRect(GrafPtr(dCtl^.dCtlWindow)^.portRect);
-
- { If they're not on a color Mac, or there's less
- than 16 colors, put up the monochrome version
- of the brag picture. BTW, the boolean short-
- circuits on non-color Macs so Chroma won't
- try to access non-existent data structures }
- IF (NOT hasColorQD) |
- (theDevice^^.gdPMap^^.pmTable^^.ctSize + 1 < 16)
- THEN
- aboutPict := GetResource('PICT',
- RsrcID(dCtl, bwChromaPicture))
- ELSE
- aboutPict := GetResource('PICT',
- RsrcID(dCtl, colorChromaPicture));
-
- IF aboutPict <> NIL THEN
- BEGIN
- { Center the picture, and draw it }
- aboutRect := PicHandle(aboutPict)^^.picFrame;
- CenterInWindow(aboutRect);
-
- DrawPicture(PicHandle(aboutPict), aboutRect);
- ReleaseResource(aboutPict);
- END;
-
- { Wait until the button isn't down (Hi Roger %-)}
- REPEAT UNTIL NOT StillDown;
-
- { Restore the contents of the window }
- InvalRect(GrafPtr(dCtl^.dCtlWindow)^.portRect);
- END;{ WITH ... }
- END;{ PROCEDURE BragALittle }
-
- VAR
- eventAt: EventPtr;
- oldPort:GrafPtr;
- localPoint:Point;
- aDevice:GDHandle;
- clippyPart:Rect;
- oldClip:RgnHandle;
- thePartCode:INTEGER;
- whichWindow:WindowPtr;
- intersections:INTEGER;
- dumbRect:Rect;
-
- BEGIN { of DRVRControl }
- WITH ChromaStorageHandle(dCtl^.dCtlStorage)^^ DO
- BEGIN
- GetPort(oldPort);
- SetPort(GrafPtr(dCtl^.dCtlWindow));
-
- CASE ctlPB^.csCode OF
- accEvent:
- BEGIN
- { Get the event pointer, through some
- coercive trickery }
- eventAt := trix(ctlPB^.CSParam).theEventPtr;
- WITH eventAt^ do
- BEGIN
- CASE what OF
- { In case of update event, draw the window }
- updateEvt:
- BEGIN
- { Save the current clip region, and
- restore it after the update }
- oldClip := NewRgn;
- GetClip(oldClip);
- BeginUpdate(WindowPtr(eventAt^.message));
- { If there's no ColorQD, just draw the
- window;otherwise cycle through all
- the devices, clipping the window to
- each device and drawing }
- IF NOT hasColorQD THEN
- DrawWindow
- ELSE BEGIN
- aDevice := GetDeviceList;
-
- { Go until the end of the device list }
- WHILE aDevice <> NIL DO
- BEGIN
- { Check for intersection of the
- content region with the device }
- WITH WindowPeek(dCtl^.dCtlWindow)^ DO
- IF SectRect(contRgn^^.rgnBBox,
- aDevice^^.gdRect,
- clippyPart)THEN
- BEGIN
- { Translate the global rect
- to local coordinates }
- GlobalToLocal(clippyPart.topLeft);
- GlobalToLocal(clippyPart.botRight);
-
- { Set the clip, so other parts of
- the window don't get blasted.
- Set theDevice field of the
- storageHandle to the device of
- interest, then draw the window. }
- ClipRect(clippyPart);
- theDevice := aDevice;
- DrawWindow;
- END;{ if intersect... }
- { Go to the next device in the
- device list }
- aDevice := aDevice^^.gdNextGD;
- END;{ while there's more devices... }
- END;{ if a color machine... }
-
- EndUpdate(WindowPtr(eventAt^.message));
-
- { Restore the clip, dump the region }
- SetClip(oldClip);
- DisposeRgn(oldClip);
-
- { Mark the window's position }
- windowPlace := WindowPeek(dCtl^.dCtlWindow)^.
- contRgn^^.rgnBBox;
- END;
- mouseDown:
- BEGIN
- localPoint := where;
- GlobalToLocal(localPoint);
-
- { Pretend this isn't a DA window to
- fool FindWindow }
- WITH WindowPeek(dCtl^.dCtlWindow)^ DO
- windowKind := -windowKind;
- thePartCode := FindWindow(where,
- WindowPtr(dCtl^.dCtlWindow));
- WITH WindowPeek(dCtl^.dCtlWindow)^ DO
- windowKind := -windowKind;
-
- { If in zoom box, zoom it, passing along
- the state of the option key... }
- IF (thePartCode=inZoomIn) OR
- (thePartCode=inZoomOut) THEN
- BEGIN
- IF TrackBox(WindowPtr(dCtl^.dCtlWindow),
- where, thePartCode) THEN
- ZoomIt(thePartCode, where,
- BitAnd(modifiers, optionKey)<>0);
- END ELSE
- { See if they clicked on the version
- number. If so, put up a brag
- picture 'til they release the
- button }
- WITH localPoint,
- GrafPtr(dCtl^.dCtlWindow)^.portRect DO
- IF (h > right - StringWidth(versID))
- AND (v < 12) THEN
- BEGIN
- BragALittle;
- END;{ if h and v in range... }
- END;{ mouseDown case }
- END;{ case what ... }
- END;{ with eventAt... }
- END;{ accEvent Case }
-
- accRun:
- BEGIN { the periodic call }
- WITH ChromaStorageHandle(dCtl^.dCtlStorage)^^ DO
- BEGIN
- { This is only a problem on multiple device
- systems }
- IF hasColorQD THEN
- BEGIN
- { Moved? If yes, invalidate the info part
- of the window }
- IF NOT EqualRect(WindowPeek(dCtl^.dCtlWindow)^.
- contRgn^^.rgnBBox,
- windowPlace) THEN
- BEGIN
- clippyPart := GrafPtr(dCtl^.dCtlWindow)^.
- portRect;
- clippyPart.left := clippyPart.left +
- clippyPart.bottom;
- InvalRect(clippyPart);
- END;{ if window moved... }
- END;{ if has color quickdraw... }
- END;{ with chromastorage... }
- END;{ accRun case... }
- END;{ case ctlPB^.csCode }
-
- SetPort(oldPort);
- DRVRControl := NoErr;
- END;{ with dctl^.dctlstorage... }
- END;{ of DRVRControl }
-
- FUNCTION DRVRPrime(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
- BEGIN
- DRVRPrime := NoErr;
- END;
-
- FUNCTION DRVRStatus(ctlPB:ParmBlkPtr;dCtl:DCtlPtr):OSErr;
- BEGIN
- DRVRStatus := NoErr;
- END;
-
-
- END. {of Chroma UNIT}
-
-